<?php
	include_once 'isLogin.php';
	
	$table_name = "users";
	
	if($_POST['submit']){
		//获取现在的时间
		$time=date("Y-m-d",time());
		//插入数据库
		$data = array('userName'=>$_POST['userName'],'address'=>$_POST['address'],'card'=>$_POST['card'],'email'=>$_POST['email'],'phoneNumber'=>$_POST['phoneNumber'],'reg_date'=>$time);
		//var_dump($data);
		if($_GET['id']!=false){
			$commonc->update($table_name,$data,"id='".$_GET['id']."'");
			$href = $_basename.'?id='.$_GET['id'];
		}else{
			$commonc->insert($table_name,$data);
			$href='users_list.php';
			$id = $commonc->insert_id();
			//$data = array('sort'=>$id);
			//$commonc->update($table_name, $data, "id='".$id."'");
		
		}
		echo $commonc->submitAlert('成功',$href);
	}
	
	//获得数据
	if($_GET['id']!=false){
		$row=$commonc->getInfo($table_name,$_GET['id']);
		$smarty->assign('row',$row);
		$smarty->assign('area',$area);
	}
	
	$smarty->display($_filename.".html");
	
?>